<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>安全警示类型管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
    <script>

    </script>
</head>

<body class="childrenBody">
    <!-- 查询条件开始 -->
<!--    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend>查询条件</legend>
    </fieldset>-->
    <blockquote class="layui-elem-quote" style="height: 50px;">
        <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">警示类型</label>
                    <div class="layui-input-inline">
                        <select name="safetyId" class="search_safety">
                            <option value="0">请选择安全警示类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">绘编标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="caseTitle" placeholder="请输入案例绘编标题"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block" style="text-align: center;">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"> <span class="layui-icon layui-icon-search"></span> 查询</button>
                        <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span> 重置</button>
                    </div>
                </div>
            </div>
        </form>
    </blockquote>
    <!--查询条件结束-->
    <!--数据表格开始-->
    <div>

        <table class="layui-hide" id="caseManagementTable" lay-filter="caseManagementTable"></table>
        <div id="caseManagementToolBar" style="display: none ;"  >
            <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-circle"></span> 添加案例绘编</button>
        </div>
        <div id="caseManagementRowBar" style="display: none">
            <input type="hidden" id="editId">
            <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-edit"></span> 修改</button>
            <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span> 删除</button>
        </div>
    </div>
    <!--数据表格结束-->

    <!-- 添加和修改的弹出层开始 -->
    <div style="display: none;padding: 5px 20px 0 0" id="addOrUpdateDiv">
        <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">警示类型</label>
                    <div class="layui-input-inline">
                        <select name="safetyId" id="safetyId"  class="search_safety"  lay-filter="providerid">
                            <option value="0">请选择警示类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">案例类型</label>
                    <div class="layui-input-inline">
                        <select name="caseType" id="caseType">
                            <option value="0">请选择案例类型</option>
                            <option value="1">案例绘编</option>
                            <option value="2">典型案例</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">案例标题</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id">
                    <input type="text" name="caseTitle" lay-verify="required" lay-reqtext="案例标题是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">案例详情</label>
                <div class="layui-input-block">
                    <!-- 加载编辑器的容器 -->
                    <textarea name="caseInfo" id="caseInfo" cols="100" rows="8" style="widith:700px; height:230px;visibility:hidden;"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否可用</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="available" value="1" title="可用" checked="">
                        <input type="radio" name="available" value="0" title="不可用" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">排序码</label>
                    <div class="layui-input-block">
                        <input type="text" id="ordernum" name="ordernum" lay-verify="required|number" autocomplete="off" placeholder="请输入排序码[>0]" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="text-align: center;">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                    <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
                </div>
            </div>
        </form>
    </div>
    <!-- 添加和修改的弹出层结束 -->
</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer',],function(){
        var $ = layui.jquery;
        var form=layui.form;
        var table = layui.table;
        var layer = layui.layer;
        //加载数据
        //初始化kindEditor富文本编辑器
        $('#dataFrm').on('hidden.bs.modal', function () {
            // 关闭Dialog前移除编辑器
            KindEditor.remove('#caseInfo');
        });
        function getKindeditor(){
            editor = KindEditor.create('textarea[name="caseInfo"]', {
                allowFileManager : true,
                allowImageUpload:true,//允许上传图片
                allowFileManager:true, //允许对上传图片进行管理
                uploadJson:"/uploadImg",
                afterUpload: function(){this.sync();}, //图片上传后，将上传内容同步到textarea中
                afterBlur: function(){this.sync();},   //失去焦点时，将上传内容同步到textarea中
                items : [
                    'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                    'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
                    'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                    'anchor', 'link', 'unlink', '|', 'about'
                ]
            });
            return editor;
        }
        var tableIns = table.render({
             elem: '#caseManagementTable'
            ,url:'/caseManagement/loadAllCaseManagement'
            ,toolbar: '#caseManagementToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                 title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '案例绘编数据表'
             ,height:'full-140'
             ,page: true
            ,cols: [ [
                 {field:'',title:'序号', type:'numbers', width: 80, align: 'center', unresize: true, sort: true}
                ,{field:'safetyName', title:'安全警示类型',align: 'center',width:160}
                ,{field:'caseTitle', title:'案例标题',align: 'center'}
                ,{field:'author', title:'发布人',width:100}
                ,{field:'createDate', title:'创建日期',width:200}
                ,{field:'available', title:'是否可用',width:80,templet:function(d){
                        return d.available==1?'<font color=blue>可用</font>':'<font color=red>不可用</font>';
                    }}
                ,{field:'ordernum', title:'排序码',width:80}
                ,{fixed: 'right', title:'操作', toolbar: '#caseManagementRowBar' ,align: 'center',width:220}
            ] ]
        });
         //模糊查询
        form.on("submit(doSearch)",function (data) {
           tableIns.reload({
               where:data.field,
               page:{
                   curr:1
               }
           });
            return false;
        });
        //加载查询条件供应商的下拉列表
        $.get("/safetyAlertType/loadAllsafetyAlertTypeForSelect",function(res){
            var data=res.data;
            var dom=$(".search_safety");
            var html='<option value="0">请选择警示类型</option>'
            $.each(data,function(index,item){
                html+='<option value="'+item.id+'">'+item.typename+'</option>'
            });
            dom.html(html);
            form.render("select");
        });
        //监听工具条事件
        table.on('toolbar(caseManagementTable)', function(obj){
            switch(obj.event){
                case 'batchDelete':
                    batchDelete();
                    break;
                case 'add':
                    admin_tiaozheng('添加案例汇编', '/safety/toAddCaseManager', '800', '600');
                    break;
            };
        });
        //监听行工具条事件
        table.on('tool(caseManagementTable)', function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'update':
                    //toEditCaseManager
                    admin_edit('修改案例汇编', '/safety/toEditCaseManager', data,'800', '600')
                    break;
                case 'delete':
                    deleteCaseManagement(data);
                    break;
            };
        });
        var mainIndex;
        var url;
        function admin_edit(title, url,data, w, h) {
            var dataId = data.id
            $("#editId").val(dataId);
            x_my_show(title, url, w, h);
        }
        //打开添加的弹出层
      /*  function openAddLayer() {
            mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['850px','550px'],
                title:'发布案例绘编',
                success:function () {
                    $("#dataFrm")[0].reset();
                    url="/caseManagement/addCaseManagement"
                    //初始化排序码
                    $.get("/caseManagement/loadCaseMaxOrderNum",function (res) {
                        $("#ordernum").val(res.value);
                    });
                    //加载渲染kindEditor富文本编辑器
                    getKindeditor();
                    editor.html("");
                }
            });
        }*/
        function admin_tiaozheng(title, url, w, h) {
            x_my_show(title, url, w, h);
        }
        //打开修改弹出层
        /*function openUpdateLayer(data) {
                mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['850px','550px'],
                title:'修改案例绘编',
                end: function(){
                    layer.closeAll();
                    KindEditor.ready(function(K) {
                        K.remove('#caseInfo');
                    });
                },
                success:function () {
                    $("#dataFrm")[0].reset();
                    form.val("dataFrm",data);
                    url="/caseManagement/updateCaseManagement"
                    //加载渲染kindEditor富文本编辑器
                    getKindeditor();
                }
            });
            $(document).delegate(".layui-layer-close1", 'click', function(event) {
                layer.closeAll();
                KindEditor.ready(function (K) {
                    K.remove('#caseInfo');
                });
            });
        }*/
        //添加和修改的提交
        form.on("submit(doSubmit)",function (data) {
            $.post(url,data.field,function (res) {
                if(res.code==20000){
                    tableIns.reload();
                }
                layer.msg(res.message);
                layer.close(mainIndex);
            })
            return false
        });

        //根据ID删除
        function deleteCaseManagement(data) {
            layer.confirm('你确定删除【'+data.caseTitle+'】吗?', {icon: 3, title:'提示'}, function(index){
            $.post("/caseManagement/deleteCaseManagement",{id:data.id},function (res) {
                        if(res.code==20000){
                            tableIns.reload();
                        }
                        layer.close(res.message);
                    })
                    layer.close(index);
                }
            )};
    });
</script>
</html>